home *** CD-ROM | disk | FTP | other *** search
/ BMUG PD-ROM BV3 / BMUG PD-ROM Version BV3 (CDRM1097900).iso / HyperCard / XCMDs⁄XFCN / Inflate XCMD / Inflate.pas < prev   
Pascal/Delphi Source File  |  1991-09-27  |  5KB  |  137 lines

  1. {XCMD: Inflate}
  2. {Written by: Stephen E. Breish}
  3. {Version: 2.0}
  4. {Date: 9/27/91}
  5. {Copyright ©1991 Stephen E. Breish}
  6. {Params:  1. Position Code (C,TL,TR,BL,BR)  2. Content Code (S,P,R)  3. String or Resource ID}
  7.  
  8. unit dummyUnit;
  9.  
  10. interface
  11.  
  12. uses
  13.     Traps, Types, Quickdraw, TextEdit, Menus, GestaltEqu, Balloons, HyperXcmd;
  14.  
  15. procedure Main (paramPtr: XCmdPtr);
  16. implementation
  17. procedure Inflate (paramPtr: XCmdPtr);
  18. FORWARD;
  19. procedure Main (paramPtr: XCmdPtr);
  20.     begin
  21.         Inflate(paramPtr);
  22.     end;
  23.  
  24. procedure Inflate (paramPtr: XCmdPtr);
  25.     var
  26.         HELPMSG: HMMessageRecord;
  27.         RCT: Rect;
  28.         MOUSE: Point;
  29.         VARCODE: integer;
  30.         result: OSErr;
  31.         response: longint;
  32.  
  33.  
  34.     procedure return (value: str255);
  35.         begin
  36.             paramPtr^.returnValue := PasToZero(paramPtr, value);            {returns the message via "the result"}
  37.             exit(Inflate);                                            {and stops execution of this XCMD}
  38.         end;
  39.  
  40.  
  41.     procedure getTargetRect;
  42.         var
  43.             rctStr: Str255;
  44.             hand: handle;
  45.         begin
  46.             hand := EvalExpr(paramPtr, 'the rect of the target');                {determine the rectangle of the target field}
  47.             ZeroToPas(paramPtr, hand^, rctStr);                            {or button so we can know where to put the}
  48.             disposHandle(hand);                                        {balloon help}
  49.             StrToRect(paramPtr, rctStr, RCT);                            {convert the string to a rect}
  50.         end;
  51.  
  52.  
  53.     procedure getPointAndVar;
  54.         var
  55.             pointCode: str255;
  56.             rctH, rctV: integer;
  57.         begin
  58.             ZeroToPas(paramPtr, paramPtr^.params[1]^, pointCode);
  59.             localToGlobal(RCT.botRight);                                    {translate the local coordinates to global}
  60.             localToGlobal(RCT.topLeft);                                    {from a point relative to the window to a point relative to the screen}
  61.  
  62.             if pointCode = 'TR' then                                        {point to the Top Right}
  63.                 begin
  64.                     SetPt(MOUSE, RCT.right, RCT.top);                            {set the point of the balloon}
  65.                     VARCODE := 6;                                            {use balloon position 6 (see IM vol VI)}
  66.                 end
  67.             else if pointCode = 'TL' then                                    {point to the Top Left}
  68.                 begin
  69.                     SetPt(MOUSE, RCT.left, RCT.top);
  70.                     VARCODE := 5;
  71.                 end
  72.             else if pointCode = 'BR' then                                    {point to the Bottom Right}
  73.                 begin
  74.                     SetPt(MOUSE, RCT.right, RCT.bottom);
  75.                     VARCODE := 0;
  76.                 end
  77.             else if pointCode = 'BL' then                                    {point to the Bottom Left}
  78.                 begin
  79.                     SetPt(MOUSE, RCT.left, RCT.bottom);
  80.                     VARCODE := 3;
  81.                 end
  82.             else if pointCode = 'C' then                                    {point to the Center}
  83.                 begin
  84.                     rctH := (RCT.right - RCT.left) div 2;                        {calculate half the width and height of the rect}
  85.                     rctV := (RCT.bottom - RCT.top) div 2;                        {to allow us to center the balloon point}
  86.                     SetPt(MOUSE, (RCT.right - rctH), (RCT.bottom - rctV));            {make the point "MOUSE" point at the center of the field/button}
  87.                     VARCODE := 0;                                            {use balloon position 0 (see IM vol VI)}
  88.                 end
  89.             else
  90.                 return('');                                                     {abort if user didn't specify the proper code}
  91.         end;
  92.  
  93.  
  94.  
  95.     procedure setHelpMsgRec;
  96.         var
  97.             typeCode: str255;
  98.             tempStr: str255;
  99.         begin
  100.             ZeroToPas(paramPtr, paramPtr^.params[2]^, TypeCode);
  101.             if typeCode = 'S' then
  102.                 begin
  103.                     HELPMSG.hmmHelpType := khmmString;                            {specify the type of the next field in the help record as a string}
  104.                     ZeroToPas(paramPtr, paramPtr^.params[3]^, HELPMSG.hmmString);    {put the string parameter into the help message record}
  105.                 end
  106.             else if typeCode = 'P' then
  107.                 begin
  108.                     HELPMSG.hmmHelpType := KhmmPict;                            {specify the type of the next field in the help record as a PICT}
  109.                     ZeroToPas(paramPtr, paramPtr^.params[3]^, tempStr);
  110.                     HELPMSG.hmmPict := StrToNum(paramPtr, tempStr);                {put the resource ID for the PICT into the help message record}
  111.                 end
  112.             else if typeCode = 'R' then
  113.                 begin
  114.                     HELPMSG.hmmHelpType := KhmmSTRRes;                            {specify the type of the next field in the help record as a STR}
  115.                     ZeroToPas(paramPtr, paramPtr^.params[3]^, tempStr);
  116.                     HELPMSG.hmmSTRRes := StrToNum(paramPtr, tempStr);                {put the resource ID for the STR into the help message record}
  117.                 end
  118.             else
  119.                 return('');                                                      {abort if user didn't specify the proper code}
  120.         end;
  121.  
  122.  
  123.     begin
  124.         result := Gestalt(gestaltHelpMgrAttr, response);                                {check if help manager is present}
  125.         if (result <> noErr) or (not BitTst(@response, 31 - gestaltHelpMgrPresent)) then        {if not then stop execution of the XCMD}
  126.             exit(Inflate);
  127.  
  128.         if (paramPtr^.paramCount <> 3) then                                         {check for proper syntax, if incorrect}
  129.             return('Form is:  Inflate <Point Code>, <Content Code>, <Content Value or ID>');        {then return the error message}
  130.  
  131.         getTargetRect;
  132.         getPointAndVar;
  133.         setHelpMsgRec;
  134.  
  135.         result := HMShowBalloon(HELPMSG, MOUSE, @RCT, nil, 0, VARCODE, kHMRegularWindow);        {show the balloon!}
  136.     end;
  137. end.